<script>
export default {
	onLaunch: function() {
		console.log('App Launch');
		this.getToken();
		// 初始化加载，先判断用户登录状态
		if (uni.getStorageSync('user')) {
			this.globalData.userInfo = JSON.parse(uni.getStorageSync('user'));
			uni.switchTab({
				url: 'pages/index/index'
			});
		} else {
			this.$u.route({
				url: 'pages/login/login'
			});
		}
	},
	onShow: function() {
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
	},
	globalData: {
		userInfo: null
	},
	methods: {
		getToken: function() {
			this.$u.api
				.getToken({
					username: '15161172354',
					pwd: '1234',
					type: 2
				})
				.then(res => {
					uni.setStorageSync('token', res.Token);
				})
				.catch(err => {
					console.log(err);
				});
		}
	}
};
</script>

<style lang="scss">
@import 'uview-ui/index.scss';
/*每个页面公共css */
</style>
